package com.example.springboot.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/* 批次号工具 */
public class LotNoUtil {

    private static final int CHAR_A = (int) '0';
    private static final int RANGE = 10;

    private static final DateFormat dateDormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    private static final String SEPARATOR = "_";
    //    拉取批次号
    private static final String LQ_PREFIX = "LQ";
    //    销售订单号
    private static final String XS_PREFIX = "XS";
    //    退货订单号
    private static final String TH_PREFIX = "TH";
    //    预入库订单号
    private static final String YR_PREFIX = "YR";

    /* 随机字符串方法，大写字母 */
    private static String randomString(int n) {
        char[] origin = new char[n];
        for (int i = 0; i < n; i++) {
            origin[i] = (char) (CHAR_A + Math.random() * RANGE);
        }
        return new String(origin);
    }

    private static String dateString() {
        return dateDormat.format(new Date());
    }

    /* 拉取批次号 */
    public static String getLQ(String pinyin,String channelPinYin) {
        StringBuilder builder = new StringBuilder();
        builder.append(LQ_PREFIX)
                .append(SEPARATOR)
                .append(pinyin)
                .append(SEPARATOR)
                .append(channelPinYin)
                .append(SEPARATOR)
                .append(dateString())
                .append(SEPARATOR)
                .append(randomString(6));
        return builder.toString();
    }

    /* 销售订单号 */
    public static String getXS(String pinyin,String channelPinYin) {
        StringBuilder builder = new StringBuilder();
        builder.append(XS_PREFIX)
                .append(SEPARATOR)
                .append(pinyin)
                .append(SEPARATOR)
                .append(channelPinYin)
                .append(SEPARATOR)
                .append(dateString())
                .append(SEPARATOR)
                .append(randomString(6));
        return builder.toString();
    }

    /* 退货订单号 */
    public static String getTH(String pinyin,String channelPinYin) {
        StringBuilder builder = new StringBuilder();
        builder.append(TH_PREFIX)
                .append(SEPARATOR)
                .append(pinyin)
                .append(SEPARATOR)
                .append(channelPinYin)
                .append(SEPARATOR)
                .append(dateString())
                .append(SEPARATOR)
                .append(randomString(6));
        return builder.toString();
    }

    /* 预入库订单号 */
    public static String getYR(String pinyin) {
        StringBuilder builder = new StringBuilder();
        builder.append(YR_PREFIX)
                .append(SEPARATOR)
                .append(pinyin)
                .append(SEPARATOR)
//                .append(pinyin)
//                .append(SEPARATOR)
                .append(dateString())
                .append(SEPARATOR)
                .append(randomString(6));
        return builder.toString();
    }


}
